package com.web.words;

import com.bean.Words;
import com.service.WordsService;
import com.tools.SensitiveWordUtils;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

public class AddWordsServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Words words=new Words();
        WordsService service=new WordsService();
        try {
            BeanUtils.populate(words,req.getParameterMap());

            String word= words.getContent();
            req.getSession().setAttribute("word",word);
            //敏感词过滤
            SensitiveWordUtils sensitiveWordUtils=new SensitiveWordUtils();
            String reWord=sensitiveWordUtils.replaceSensitiveWord(word,2);
            System.out.println(reWord);
            words.setReContent(reWord);
            req.getSession().setAttribute("reWord",reWord);//过滤后评论

            service.addremark(words);
            req.getRequestDispatcher("/ListWords").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("留言添加失败！！！");
        }



    }

}
